package com.example.management.service.impl;

import com.example.management.mapper.ManagerMapper;
import com.example.management.pojo.Manager;
import com.example.management.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ManagerServiceImpl implements ManagerService {
    @Autowired
    private ManagerMapper managerMapper;


    @Override
    public List<Manager> getAllManager() {
        return managerMapper.getAllManager();
    }

    @Override
    public String login(Manager manager) {

        try {
            Manager manager1 = managerMapper.login(manager);
            return "登录成功！你的权限是:" + manager1.getPower();
        } catch (Exception e) {
            e.printStackTrace();
            return "登录失败";
        }
    }

    @Override
    public String signUp(Manager manager) {
        try {
            managerMapper.signUp(manager);
            return "注册成功";
        } catch (Exception e) {
            return "注册失败";
        }
    }

    @Override
    public String changeMes(Manager manager, String newName, String newPassword) {
        if (managerMapper.login(manager) != null) {
            managerMapper.changeMes(manager, newName, newPassword);
            try {
                return "修改成功！新名字：" + newName + "    新密码：" + newPassword;
            } catch (Exception e) {
                return "修改失败";
            }
        } else
            return "修改失败";
    }
}
